using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;

namespace DNAide.Website.UserControls
{
	public partial class SiteMapUC : System.Web.UI.UserControl
	{
		protected void Page_Load(object sender, EventArgs e)
		{
			StringWriter sw = new StringWriter();
			HtmlTextWriter writer = new HtmlTextWriter(sw);

			writer.WriteFullBeginTag("h3");
			writer.WriteBeginTag("a");
			writer.WriteAttribute("href", SiteMap.RootNode.Url);
			writer.Write(HtmlTextWriter.TagRightChar);
			writer.Write(SiteMap.RootNode.Title);
			writer.WriteEndTag("a");
			writer.WriteEndTag("h3");

			foreach (SiteMapNode sectionNode in SiteMap.RootNode.ChildNodes)
			{
				writer.WriteFullBeginTag("h3");
				writer.WriteBeginTag("a");
				writer.WriteAttribute("href", sectionNode.Url);
				writer.Write(HtmlTextWriter.TagRightChar);
				writer.Write(sectionNode.Title);
				writer.WriteEndTag("a");
				writer.WriteEndTag("h3");
				if (sectionNode.ChildNodes.Count > 0)
				{
					writer.WriteFullBeginTag("ul");
					foreach (SiteMapNode childNode in sectionNode.ChildNodes)
					{
						writer.WriteFullBeginTag("li");
						writer.WriteBeginTag("a");
						writer.WriteAttribute("href", childNode.Url);
						writer.Write(HtmlTextWriter.TagRightChar);
						writer.Write(childNode.Title);
						writer.WriteEndTag("a");
						writer.WriteEndTag("li");
					}
					writer.WriteEndTag("ul");
				}
			}

			this.SiteMapHtml.Text = sw.GetStringBuilder().ToString();
		}
	}
}